# Author: Yubin Lim(purewell@gmail.com)
# Date: 2008-01-18
# License: BSD License
# Copyright: All rights reserved by Yubin Lim.

include(CheckIncludeFile)
include(CheckFunctionExists)
include(CheckTypeSize)

check_include_file("sys/statvfs.h" HAVE_SYS_STATVFS_H)
check_include_file("statvfs.h" HAVE_STATVFS_H)

if ( "${HAVE_SYS_STATVFS_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "sys/statvfs.h")
endif ( "${HAVE_SYS_STATVFS_H}" )

if ( "${HAVE_STATVFS_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "statvfs.h")
endif ( "${HAVE_STATVFS_H}" )

check_function_exists(statvfs HAVE_STATVFS)
check_function_exists(fstatvfs HAVE_FSTATVFS)
check_type_size("struct statvfs" HAVE_STATVFS_T)

check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("stat.h" HAVE_STAT_H)

if ( "${HAVE_SYS_STAT_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "sys/stat.h")
endif ( "${HAVE_SYS_STAT_H}" )

if ( "${HAVE_STAT_H}" )
	set(CMAKE_EXTRA_INCLUDE_FILES "stat.h")
endif ( "${HAVE_STAT_H}" )

check_function_exists(stat HAVE_STAT)
check_function_exists(lstat HAVE_LSTAT)
check_function_exists(fstat HAVE_FSTAT)
check_type_size("struct stat" HAVE_STAT_T)

set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h")
check_type_size(dev_t __PW_HAVE_DEV_T)
check_type_size(ino_t __PW_HAVE_INO_T)
check_type_size(mode_t __PW_HAVE_MODE_T)
check_type_size(nlink_t __PW_HAVE_NLINK_T)
check_type_size(uid_t __PW_HAVE_UID_T)
check_type_size(gid_t __PW_HAVE_GID_T)
check_type_size(off_t __PW_HAVE_OFF_T)
check_type_size(blksize_t __PW_HAVE_BLKSIZE_T)
check_type_size(blkcnt_t __PW_HAVE_BLKCNT_T)

configure_file(purewell.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}/purewell.hpp")
configure_file(types.hpp.in "${CMAKE_CURRENT_SOURCE_DIR}/types.hpp")
add_subdirectory(code)
file(GLOB files "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
install(FILES ${files} DESTINATION include/purewell)
